package com.tianqu.tms.entity;

import java.lang.reflect.InvocationTargetException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import com.tianqu.tms.core.base.TmsEntity;
import com.tianqu.tms.core.exception.TmsDaoException;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.util.CopyFile;
import com.tianqu.tms.core.util.MD5Util;
import com.tianqu.tms.core.util.Registry;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.dao.MarketCarGateInfoDao;
import com.tianqu.tms.dao.MarketCarHandleInfoDao;
import com.tianqu.tms.dao.TmsDao;
import com.tianqu.tms.dto.MarketCarGateInfoDto;
import com.tianqu.tms.dto.MarketCarHandleDto;

/**
 * @author mufeiyu
 * 库存车辆特殊处理记录信息entity
 */
public class MarketCarHandleInfo extends TmsEntity{

	/**
	 * 
	 */
	private static final long serialVersionUID = 4888533395413239006L;
	@Override
	public void save() throws TmsDaoException, TmsException {}
	private long id;
	// 车辆编号
	private String serial;
	// 操作类型
	private int handleType;
	private String handleTypes;
	// 是否推送
	private int isPush;
	private String isPushs;
	// 推送内容
	private String pushContent;
	// 更新用户
	private int updateUserId;
	// 更新时间
	private Timestamp updateTime;
	private String updateTimes;
	// 序号
	private int num;
	// 操作员姓名
	private String realName;
	// 标志FLAG
	private int cssFlag;
	// 办理人照片
	private String photo;
	
	// 备注
	private String remark;
	
	public static MarketCarHandleInfo getInstance() {
		MarketCarHandleInfo marketCarHandleInfo = new MarketCarHandleInfo();
		marketCarHandleInfo.setExisting(false);
		return marketCarHandleInfo;
	}
	
	/**
	 * 根据流水号查询库存特殊记录信息
	 * @return
	 * @throws TmsDaoException
	 */
	public List<MarketCarHandleInfo> findHandleInfoBySerial(String serial)throws TmsDaoException{
		
		MarketCarHandleInfoDao mDao = (MarketCarHandleInfoDao)TmsDao.getInstance(TmsDao.TMS_MARKET_CAR_HANDLEINFO);
		
		List<MarketCarHandleInfo> list = new ArrayList<MarketCarHandleInfo>();
		Codes code = Codes.getInstance();
		int i = 1;
		List<MarketCarHandleDto> dtoList = mDao.findHandleInfoBySerial(serial);		
		for(MarketCarHandleDto dto:dtoList){
			MarketCarHandleInfo marketCarHandleInfo = new MarketCarHandleInfo();
			marketCarHandleInfo.setNum(dto.getNum());
			marketCarHandleInfo.setHandleTypes(code.getItemValueByItemIdAndItemCode(Codes.HANDLETYPE_TYPE, dto.getHandleType()));
			marketCarHandleInfo.setIsPushs(code.getItemValueByItemIdAndItemCode(Codes.ISPUSH_TYPE, dto.getIsPush()));
			marketCarHandleInfo.setPushContent(dto.getPushContent());
			marketCarHandleInfo.setPhoto(dto.getPhoto());
			marketCarHandleInfo.setRealName(dto.getUserName());
			marketCarHandleInfo.setUpdateTimes(StringUtil.getTimeByTimeStamp(dto.getUpdateTime()));
			marketCarHandleInfo.setRemark(dto.getRemark());
			if(i%2 == 0){
				marketCarHandleInfo.setCssFlag(2);
			} else {
				marketCarHandleInfo.setCssFlag(1);
			}			
			marketCarHandleInfo.setNum(i);
			i++;
			list.add(marketCarHandleInfo);			
		}
		return list;
	}
	public void insertCarHandleInfo(MarketCarHandleInfo carHandleInfo)throws TmsDaoException{
		MarketCarHandleInfoDao dao = (MarketCarHandleInfoDao)TmsDao.getInstance(TmsDao.TMS_MARKET_CAR_HANDLEINFO);
		MarketCarHandleDto dto = new MarketCarHandleDto();
		dto.setSerial(carHandleInfo.getSerial());
		dto.setHandleType(carHandleInfo.getHandleType());
		dto.setIsPush(carHandleInfo.getIsPush());
		dto.setPhoto(carHandleInfo.getPhoto());
		dto.setUpdateUserId(carHandleInfo.getUpdateUserId());
		dto.setPushContent(carHandleInfo.getPushContent());
		dto.setRemark(carHandleInfo.getRemark());
		dao.insertCarHandleInfo(dto);
	}

	public void setId(long id) {
		this.id = id;
	}

	public long getId() {
		return id;
	}

	public void setSerial(String serial) {
		this.serial = serial;
	}

	public String getSerial() {
		return serial;
	}

	public void setHandleType(int handleType) {
		this.handleType = handleType;
	}

	public int getHandleType() {
		return handleType;
	}

	public void setHandleTypes(String handleTypes) {
		this.handleTypes = handleTypes;
	}

	public String getHandleTypes() {
		return handleTypes;
	}

	public void setIsPush(int isPush) {
		this.isPush = isPush;
	}

	public int getIsPush() {
		return isPush;
	}

	public void setIsPushs(String isPushs) {
		this.isPushs = isPushs;
	}

	public String getIsPushs() {
		return isPushs;
	}

	public void setPushContent(String pushContent) {
		this.pushContent = pushContent;
	}

	public String getPushContent() {
		return pushContent;
	}

	public void setUpdateUserId(int updateUserId) {
		this.updateUserId = updateUserId;
	}

	public int getUpdateUserId() {
		return updateUserId;
	}

	public void setUpdateTime(Timestamp updateTime) {
		this.updateTime = updateTime;
	}

	public Timestamp getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTimes(String updateTimes) {
		this.updateTimes = updateTimes;
	}

	public String getUpdateTimes() {
		return updateTimes;
	}

	public void setNum(int num) {
		this.num = num;
	}

	public int getNum() {
		return num;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public String getRealName() {
		return realName;
	}

	public void setCssFlag(int cssFlag) {
		this.cssFlag = cssFlag;
	}

	public int getCssFlag() {
		return cssFlag;
	}

	/**
	 * @param photo the photo to set
	 */
	public void setPhoto(String photo) {
		this.photo = photo;
	}

	/**
	 * @return the photo
	 */
	public String getPhoto() {
		return photo;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getRemark() {
		return remark;
	}
}